﻿using Mengsk.ProxyDelivery.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Mengsk.ProxyDelivery.App.Extenstions;
using Mengsk.ProxyDelivery.Service;

namespace Mengsk.ProxyDelivery.App.UI.Order
{
    /// <summary>
    /// OrderGoodsCreateReturn.xaml 的交互逻辑
    /// </summary>
    public partial class OrderGoodsCreateReturn : Window
    {
        public OrderGoods OrderGoods { get; set; }

        OrderChangeService orderChangeService = ServiceContainer.GetService<OrderChangeService>();

        public OrderGoodsCreateReturn()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string deliveryCompany = this.cbbDeliveryCompanies.Text.Trim();
                string deliveryNumber = this.tbDeliveryNumber.Text.Trim();
                OrderChangeReason rr = OrderChangeReason.Day7;// this.cbbReason.GetSelectedEnum<OrderChangeReason>();
                int count = int.Parse(this.tbCount.Text.Trim());
                string sellerComment = "";// this.tbSellerComment.Text.Trim();

                if (string.IsNullOrWhiteSpace(deliveryCompany) || string.IsNullOrWhiteSpace(deliveryNumber) || count < 1)
                {
                    MessageBox.Show("请输入相应信息");
                    return;
                }

                if (rr == OrderChangeReason.None)
                {
                    MessageBox.Show("请选择类型");
                    return;
                }

                orderChangeService.Create(this.OrderGoods.OrderId, this.OrderGoods.Id, deliveryCompany, deliveryNumber, OrderChangeType.Retreat, rr, count, sellerComment);
                MessageBox.Show("创建成功");
                this.DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.cbbDeliveryCompanies.ItemsSource = Domain.DeliveryCompanyHelper.GetDeliveryCompany();
            //this.cbbReason.Bind<OrderChangeReason>();
        }
    }
}
